<?php

declare (strict_types=1);

namespace App\Common\Modular\Administer\Model;

use Core\Basics\BasicsModel;
use Zms\HyperfCasts\{IpCasts, StrtotimeCasts};
use Hyperf\Database\Model\Relations\HasOne;

/**
 * @property int $id
 * @property int $user_id 登录账号
 * @property string $type 登录类型
 * @property int $time 登录时间
 * @property string $ip 登录IP
 * @property string $ascription IP属地
 * @property string $os 操作系统
 * @property string $browser 浏览器
 */
class LoginLogModel extends BasicsModel
{
    public const CREATED_AT = 'time';
    public const UPDATED_AT = null;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'administer_login_log';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'int', 'user_id' => 'integer', 'time' => StrtotimeCasts::class,'ip'=>IpCasts::class];

    /**
     * 关联操作员
     * @return HasOne
     */
    public function user(): HasOne
    {
        return $this->hasOne(UserModel::class, 'id', 'user_id');
    }
}
